<div class="layui-form" lay-filter="form-list" id="form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">宝贝名称</label>
        <div class="layui-input-block">
            <input type="text" autocomplete="off" class="layui-input" value="{$baby['name']|default=''}" disabled>
            <input type="text" hidden value="{$baby['id']}" name="baby_id">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>测量时间</label>
        <div class="layui-input-block">
            <input type="text" name="measure_time"  readonly="readonly" id="measure_time" lay-verify="required" autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>食用周期(月)</label>
        <div class="layui-input-block">
            <input type="number" name="eat_cycle" lay-verify="required"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>宝贝身高(cm)</label>
        <div class="layui-input-block">
            <input type="text" name="height" lay-verify="required"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>宝贝体重(kg)</label>
        <div class="layui-input-block">
            <input type="text" name="weight" lay-verify="required"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>乐补高食用量(粒)</label>
        <div class="layui-input-block">
            <input type="number" name="lebugao" lay-verify="required"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>饮食习惯</label>
        <div class="layui-input-block">
            <input type="text" name="eat_habits" lay-verify="required"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>运动方式</label>
        <div class="layui-input-block">
            <input type="text" name="exercise_mode" lay-verify="required"  autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">骨龄</label>
        <div class="layui-input-block">
            <input type="text" name="bone_age"   autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">既往测量时间(3个月前)</label>
        <div class="layui-input-block">
            <input type="text" name="before_measure_time"  id="before_measure_time"  readonly="readonly" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">既往测量身高(cm)</label>
        <div class="layui-input-block">
            <input type="number" value="" name="before_height" autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">注意事项</label>
        <div class="layui-input-block">
            <input type="text" name="note"  class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="form-submit" id="form-submit" value="确认添加">
        <input type="hidden" name="id" value="{$data['id']|default=''}">
    </div>
</div>
<script>
    //Demo
    layui.use(['form','upload','layer','layedit','laydate'], function(){
        var $ = layui.$
            ,form = layui.form
            ,upload = layui.upload
            ,layedit = layui.layedit
            ,layer = layui.layer
            ,laydate = layui.laydate;

        var ins1 = laydate.render({
            elem: '#measure_time'
            ,trigger: 'click'
            //,type: 'date' //默认，可不填
        });

        var ins2 = laydate.render({
            elem: '#before_measure_time'
            ,trigger: 'click'
            //,type: 'date' //默认，可不填
        });


        // 富文本编辑器
        layedit.set({
            uploadImage: {
                url: "{:url('upload/layuiUploads')}" //接口url
            }
        });
        var content = layedit.build('content');

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: "{:url('upload/ajaxUploads')}"+'?dir=rich_text'
            ,accept: "images"
            ,field: "image"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#test-upload-normal-img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }else{
                    $('#image_src').val(res.data[0].path)
                }

                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#test-upload-demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
                });
            }
        });

        //监听提交
        form.on('submit(form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            field.content = layedit.getContent(content);
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.post("{:url('admin/baby_grow_log/save')}",field,function (ret) {
                if (ret.code == 0){
                    layer.msg(ret.msg,{icon:6,time:1000},function () {
                        parent.layui.table.reload('LAY-app-content-list'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    })
                }else{
                    layer.msg(ret.msg,{icon:5,time:1000})
                }
            });

            return false;
        });
    });

</script>
